package com.test.practice.io.bytestream;

import lombok.Cleanup;

import java.io.*;

/**
 * FileInputStream 和 FileOutputStream  实现非文本文件复制
 *
 * @Description: FileInputStream 和 FileOutputStream  实现非文本文件复制
 * =======================
 * @Author: Jovi
 * =======================
 * @Date: Created in 2023-02-09
 * =======================
 * @Version: 1.1.2.0
 */
public class FileCopyDemo {

    public static void main(String[] args) throws Exception {

        File srcFile = new File("1.png");
        File dstFile = new File("2.png");

        @Cleanup FileInputStream fis = new FileInputStream(srcFile);
        @Cleanup FileOutputStream fos = new FileOutputStream(dstFile);

        byte[] bytes = new byte[5];
        int len;
        while ((len = fis.read(bytes)) != -1) {
            fos.write(bytes, 0, len);
        }

    }
}
